100 'INTERPRETED BASIC PROGRAM THAT CALLS OPT-TECH SORT
105 'WITH A RECORD AT A TIME
110 'THE OPEN AND FIELD STATEMENT BELOW OBTAIN A RECORD BUFFER
120 OPEN "NUL" FOR RANDOM AS #1
130 FIELD #1, 100 AS IOAREA$
150 OPEN "SAMP.DAT" FOR INPUT AS #2  'SAMP.DAT RECORDS ARE USED AS DATA
152 '
153 'OPEN SORTIBAS.SEG TO GET SEGMEMT ADDRESS OF SORTIBAS
155 OPEN "SORTIBAS.SEG" FOR INPUT AS #3
157 INPUT #3, SEGADDR
159 DEF SEG   = SEGADDR
160 CLOSE 3
162 RSIBAS = 6
165 '
170 'INITIALIZATION CALL (FUNCTION 1)
180 FUNC% = 1
190 CTLSTMT$ = "S(1,10,C,D)"
200 LSET IOAREA$ = CTLSTMT$
205 IOAREA.ADDR% = VARPTR(#1)
210 IOAREA.LEN% = LEN(CTLSTMT$)
220 CALL RSIBAS(FUNC%, IOAREA.ADDR%, IOAREA.LEN%, RETCODE%)
230 IF RETCODE% <> 0 GOTO 800
240 '
250 'PASS RECORDS TO OPT-TECH SORT (FUNCTION 2)
260 FUNC% = 2
270 IF EOF(2) GOTO 350
280 LINE INPUT #2, TESTDATA$
290 IOAREA.LEN% = LEN(TESTDATA$)
300 LSET IOAREA$ = TESTDATA$
310 CALL RSIBAS(FUNC%, IOAREA.ADDR%, IOAREA.LEN%, RETCODE%)
320 IF RETCODE% <> 0 GOTO 800
330 GOTO 270
340 '
350 'GET SORTED RECORDS BACK FROM OPT-TECH SORT (FUNCTION 3)
360 FUNC% = 3
370 CALL RSIBAS(FUNC%, IOAREA.ADDR%, IOAREA.LEN%, RETCODE%)
380 IF RETCODE% = 1 GOTO 900
390 IF RETCODE% > 1 GOTO 800
400 TESTDATA$ = MID$(IOAREA$, 1, IOAREA.LEN%)
410 PRINT TESTDATA$
420 GOTO 370
800 '
810 'ERROR AREA - PRINT RETURN CODE AND END
820 PRINT "SORT RETURN CODE =", RETCODE%
900 END

